package entities;

import view.ChessBoard;

import javax.swing.*;
import java.awt.*;

/***
 * Author: Mr.Zhao, Time: 2018/5/9/15:56
 * Description: 用于记录棋子上次的坐标点，并在棋盘上绘出
 */
public class RecordPoint extends JLabel {
    private Color pointColor;
    private Point position;
    /* 内部圆圈的直径 */
    private int circleDiameter = 16;
    /* 外部圆环的直径 */
    private int loopDiameter = 30;

    public RecordPoint(Color pointColor, Point position) {
        ChessBoard chessBoard = ChessBoard.getInstance();
        this.pointColor = pointColor;
        this.position = position;
        int x = position.x;
        int y = position.y;
        /* 将其设置到棋盘的位置 */
        this.setBounds(chessBoard.getMargin() + x * chessBoard.getCellWidth() - loopDiameter / 2,
                chessBoard.getMargin() + y * chessBoard.getCellHeight() - loopDiameter / 2,
                loopDiameter,
                loopDiameter);
    }

    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(pointColor);
        g.fillOval((loopDiameter - circleDiameter) / 2, (loopDiameter - circleDiameter) / 2, circleDiameter, circleDiameter);
        g.drawOval(0, 0, loopDiameter, loopDiameter);
    }
}
